package com.xgj.rabbitMq;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

//rabbitmq消息消费者
@Service
public class RabbitMQConsumer {

    @Autowired
    private RestTemplate restTemplate;

    private static final String CONTROLLER_URL = "http://localhost:9999/api/random-users/import";

    //还是直接用控制台发送消息，注意登录的用户是guest
    //监听
    @RabbitListener(queues = "import-users-queue")
    public void receiveMessage(String message) {
        // 调用 Controller 接口
        System.out.println("rabbitmq消息消费者："+message);
        restTemplate.getForObject(CONTROLLER_URL, String.class);
    }
}
